<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
	</head>
	<body>
		<h1>ajax-post入门案例</h1>
		<script src="../js/axios.js"></script>
		<script>
			//1.Axios优化   公共路径部分
			axios.defaults.baseURL="http://localhost:8080";					
			/**
			 * 2.axios的post请求
			 *   用时？ 新增
			 *  user js对象  json串 java对象
			 *      
			 * */	 
			// let user = { id: 120,name: "tomcat猫",age: 39}
			// 		axios.post("/axios/saveUser",user)  //post不能使用这个方法 {params:user}
			// 		.then(function(promise){
			// 			console.log(promise.data)
			// 			axios.post("/axios/saveUser",user)  
			// 			.then(function(promise){
			// 				console.log(promise.data)	
			// 				axios.post("/axios/saveUser",user)
			// 				.then(function(promise){
			// 					console.log(promise.data)
			// 					axios.post("/axios/saveUser",user)
			// 					.then(function(promise){
			// 						console.log(promise.data)					
			// 					})						
			// 				})					
			// 			})					
			// 		})
		
				 //回调地狱 * 优化
						
				async function saveUser2(){
								let user = {id: 102,name: "mcat猫",age: 39}
								let promise = await axios.post("/axios/saveUser2",user)
								console.log(promise.data)
								  let { data:result,status:code} = await axios.post("/axios/saveUser2",user)
								  console.log(result)
								  console.log(code)							
							}							
							saveUser2()
													
								let user3 = {id: 10,name: "tomcat猫猫"}
								let user2 = {id: 1200,name: "tomcat黑猫",age: 19}
											axios.post("/axios/saveUser2",user2)
												 .then(function(promise){
													console.log(promise.data)
												 })
											axios.post("/axios/saveUser2",user3)
												 .then(	promise => {
													console.log(promise.data)
												 })	 							
		</script>
	</body>
</html>
